﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;

namespace T_test
{
    public partial class Admin : System.Web.UI.Page
    {
        public SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnName"].ToString());
        public SqlCommand cmd = new SqlCommand();
        public DataRow dr;
        public DataTable dt;
        public DataSet ds = new DataSet();
        public OleDbConnection odc = new OleDbConnection(ConfigurationManager.AppSettings["OracleConn"].ToString());
        OleDbCommand ocmd = new OleDbCommand();
        public DataSet ods = new DataSet();
        public DataTable odt;
        public DataRow odr;
        public string msg;
        protected void Page_Load(object sender, EventArgs e)
        {
            cmd.CommandText = "select * from TAuth order by foaid desc";
            try
            {
                cmd.Connection = conn;
                conn.Open();
                SqlDataAdapter sda = new SqlDataAdapter(cmd);
                sda.Fill(ds,"tauth");

                dt = ds.Tables[0];
                dt.Columns.Add("oaHave", typeof(System.String));

                //OA Oracle
                odc.Open();
                ocmd.Connection = odc;
                ocmd.CommandText = "select id,loginid,lastname,mobile,certificatenum from hrmresource where id in (select resourceid from HrmRoleMembers where roleid = '661')";
                OleDbDataAdapter oda = new OleDbDataAdapter(ocmd);
                oda.Fill(ods);
                odt = ods.Tables[0];

                //Edit DataTable
                for (int i = 0; i < dt.Rows.Count; i++) {
                    dr = dt.Rows[i];
                    dr.BeginEdit();
                    for (int j = 0; j < odt.Rows.Count; j++) {
                        odr = odt.Rows[j];
                        if (dr["fname"].ToString() == odr["lastname"].ToString()) {
                            dr["oaHave"] = "有";
                        }
                    }
                    dr.EndEdit();
                }
                
                conn.Close();
            }
            catch (Exception er)
            {
                msg = er.Message;
            }
            ds.Tables.Remove("tauth");
            ds.Tables.Add(dt);
            //绑定DS到Repeater
            rptAuth.DataSource = ds;
            rptAuth.DataBind();

            ocmd.Dispose();
            odc.Close();
        }
    }
}